package com.example.pingtools.base

import android.app.AlertDialog
import android.content.Context
import android.opengl.Visibility
import android.util.Log
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import android.widget.Toast
import androidx.core.view.isVisible
import com.example.mygreendao.GreenDaoManager
import com.example.pingtools.MainActivity
import com.example.pingtools.R
import com.example.pingtools.bean.FloderBean
import com.example.pingtools.bean.isupdate
import com.example.pingtools.util.PingUtil
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.layout_addfloder.*
import kotlinx.android.synthetic.main.layout_addfloder.view.*
import kotlinx.android.synthetic.main.layout_addip.*
import kotlinx.android.synthetic.main.layout_addip.tv_cancle
import kotlinx.android.synthetic.main.layout_addip.view.*
import kotlinx.android.synthetic.main.layout_addip.view.tv_cancle
import kotlinx.android.synthetic.main.layout_addip.view.tv_start
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import org.greenrobot.eventbus.EventBus
import java.lang.Exception
import java.net.ConnectException
import java.net.InetSocketAddress
import java.net.Socket

class dialogfloder(context: Context) : AlertDialog(context),
    View.OnClickListener {

    /* constructor(context: Context?, line: Int?) : this(context!!) {

         tv_grid_num.text = (line.toString() + "-")

     }*/

    init {
        var layout = LayoutInflater.from(context).inflate(R.layout.layout_addfloder, null)

        setView(layout)

        //设置点击别的区域关闭页面
        setCancelable(true)

        layout.tv_ok.setOnClickListener(this)
        layout.tv_cancle.setOnClickListener(this)
    }

    override fun show() {
        val params: WindowManager.LayoutParams = window!!.attributes
        params.width = 500
        params.gravity = Gravity.CENTER
        window!!.attributes = params
        window!!.setBackgroundDrawableResource(android.R.color.transparent)

        super.show()
    }

    override fun onClick(v: View?) {
        when (v) {
            tv_ok ->{
                var floderBean=FloderBean()
                floderBean.name=et_name.text.toString()
                GreenDaoManager(context).addfloder(floderBean)
                EventBus.getDefault().postSticky(isupdate(1,false,0))
                dismiss()
            }
            tv_cancle -> {
                dismiss()
            }
        }

    }

}
